//
//  LHManager.m
//  LazyHome
//
//  Created by yh on 2018/5/8.
//  Copyright © 2018年 yh. All rights reserved.
//

#import "LHManager.h"
#import "ServerTCPManager.h"
#import "TestTool.h"
#import "LHCmd.h"
#import <MJExtension/MJExtension.h>
#import <UIDevice+FCUUID.h>

@implementation LHManager

+ (instancetype)shareManager{
    static dispatch_once_t onceToken;
    static LHManager *shareInstance = nil;
    dispatch_once(&onceToken, ^{
        shareInstance = [[LHManager alloc] init];
    });
    return shareInstance;
}


- (void)login{
    NSString *uuid = [UIDevice currentDevice].uuid;
    ushort cmd = CMD_P2S_LOGIN;
    LHMessage *ms = [LHMessage messageWithData:[TestTool testDataWithCmd:cmd] cmd:cmd];
    NSDictionary *dict = @{
                           @"uuid":uuid,
                           };
    ms = [LHMessage messageWithData:[dict mj_JSONData] cmd:cmd];
    [[ServerTCPManager shareManager] sendMessage:ms toClient:[ServerTCPManager shareManager].client success:^(LHMessage *message) {
        
    } failure:^{
        
    }];
}

- (void)queryDevices{
    NSString *uuid = [UIDevice currentDevice].uuid;
    ushort cmd = CMD_P2S_GETDEVICES;
    NSDictionary *dict = @{
                           @"uuid":uuid,
                           };
    LHMessage *ms = [LHMessage messageWithData:[dict mj_JSONData] cmd:cmd];
    [[ServerTCPManager shareManager] sendMessage:ms toClient:[ServerTCPManager shareManager].client success:^(LHMessage *message) {
        
    } failure:^{
        
    }];
}


- (void)getDeviceBaseInfoWithDeviceId:(NSString *)deviceId{
    
    ushort cmd = CMD_P2S_GETDEVICE_BASEINFO;
    NSDictionary *dict = @{
                           @"deviceId":deviceId,
                           };
    LHMessage *ms = [LHMessage messageWithData:[dict mj_JSONData] cmd:cmd];
    [[ServerTCPManager shareManager] sendMessage:ms toClient:[ServerTCPManager shareManager].client success:^(LHMessage *message) {
        
    } failure:^{
        
    }];
}



- (void)getDeviceStateInfoWithDeviceId:(NSString *)devId{
    ushort cmd = CMD_P2S_GETDEVICE_STATUSINFO;
    NSDictionary *dict = @{
                           @"deviceId":devId,
                           @"deviceType":@(DEVICETYPE_8RELAY)
                           };
    LHMessage *ms = [LHMessage messageWithData:[dict mj_JSONData] cmd:cmd];
    [[ServerTCPManager shareManager] sendMessage:ms toClient:[ServerTCPManager shareManager].client success:^(LHMessage *message) {
        
    } failure:^{
        
    }];
}

- (void)change8RelayWithDeviceId:(NSString *)deviceId status:(unsigned char)status{
    ushort cmd = CMD_P2S_HANDLEP0;
    LHMessage *ms = [LHMessage messageWithData:[TestTool testDataWithCmd:cmd] cmd:cmd];
    NSDictionary *dict = @{
                           @"p0Status":@(status),
                           @"devID":deviceId
                           };
    ms = [LHMessage messageWithData:[dict mj_JSONData] cmd:cmd];
    [[ServerTCPManager shareManager] sendMessage:ms toClient:[ServerTCPManager shareManager].client success:^(LHMessage *message) {
        
    } failure:^{
        
    }];
}

- (void)changeDeviceStatusWithDeviceId:(NSString *)deviceId deviceType:(DEVICETYPE)deviceType status:(NSDictionary *)status{
    ushort cmd = CMD_P2S_CHANGEDEVICE_STATUS;
    LHMessage *ms = [LHMessage messageWithData:[TestTool testDataWithCmd:cmd] cmd:cmd];
    NSDictionary *dict = @{
                           @"deviceId":deviceId,
                           @"deviceType":@(deviceType),
                           @"status":status
                           };
    ms = [LHMessage messageWithData:[dict mj_JSONData] cmd:cmd];
    [[ServerTCPManager shareManager] sendMessage:ms toClient:[ServerTCPManager shareManager].client success:^(LHMessage *message) {
        
    } failure:^{
        
    }];
}

@end
